using Core.SimpleTemp.Application;
using Core.SimpleTemp.Common.Authorization;
using Core.SimpleTemp.Common.PagingQuery;
using Core.SimpleTemp.Mvc.Api.Internal;
using Core.Toolkit.Authorization;
using Core.Toolkit.Core;
using Core.Toolkit.Core.Api;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;
using System.Linq;
using Core.SimpleTemp.Application.YH.Dto;

namespace Core.SimpleTemp.Api.Api
{
    /// <summary>
    /// YH_StandingBook
    ///</summary>
    [ApiExplorerSettings(GroupName = "Sys")]//swagger分类标签
    [Route("api/[controller]")]//路由说明
    [EnableCors("any")]//跨域规则
    [ApiController]//APi标识Controller
    [Authorize]//验证是否登录
    public class YH_StandingBookChartController : CoreApiController
    {
        private readonly YH_StandingBookChartService _service;
        /// <summary>
        /// YH_StandingBook
        ///</summary>
        public YH_StandingBookChartController(YH_StandingBookChartService service)
        {
            _service = service;
        }

        [HttpGet("GetRiskTypeChart")]
        [HttpPost("GetRiskTypeChart")]
        [PermissionFilter(nameof(YH_StandingBookChartController) + "_" + nameof(YH_StandingBookChartController.GetRiskTypeChart), AuthorizationConst.LIST)]
        public async Task<IActionResult> GetRiskTypeChart(string DiscoveryTimeStart, string DiscoveryTimeEnd, string RiskLevel, string Department)
        {
            if (DiscoveryTimeStart == "undefined")
            {
                DiscoveryTimeStart = "";
            }
            if (DiscoveryTimeEnd == "undefined")
            {
                DiscoveryTimeEnd = "";
            }
            if (RiskLevel == "undefined")
            {
                RiskLevel = "";
            }
            if (Department == "undefined")
            {
                Department = "";
            }
            var result = _service.GetRiskTypeChart(DiscoveryTimeStart, DiscoveryTimeEnd, RiskLevel, Department);
            return this.JsonSuccess(result);
        }

        [HttpGet("GetRiskLevelChart")]
        [HttpPost("GetRiskLevelChart")]
        [PermissionFilter(nameof(YH_StandingBookChartController) + "_" + nameof(YH_StandingBookChartController.GetRiskLevelChart), AuthorizationConst.LIST)]
        public async Task<IActionResult> GetRiskLevelChart(string DiscoveryTimeStart, string DiscoveryTimeEnd, string RiskType, string Department)
        {
            if (DiscoveryTimeStart == "undefined")
            {
                DiscoveryTimeStart = "";
            }
            if (DiscoveryTimeEnd == "undefined")
            {
                DiscoveryTimeEnd = "";
            }
            if (RiskType == "undefined")
            {
                RiskType = "";
            }
            if (Department == "undefined")
            {
                Department = "";
            }
            var result = _service.GetRiskLevelChart(DiscoveryTimeStart, DiscoveryTimeEnd, RiskType, Department);
            return this.JsonSuccess(result);
        }
        [HttpGet("GetRiskFactoryChart")]
        [HttpPost("GetRiskFactoryChart")]
        [PermissionFilter(nameof(YH_StandingBookChartController) + "_" + nameof(YH_StandingBookChartController.GetRiskFactoryChart), AuthorizationConst.LIST)]
        public async Task<IActionResult> GetRiskFactoryChart(string DiscoveryTimeStart, string DiscoveryTimeEnd, string RiskType, string RiskLevel)
        {
            if (DiscoveryTimeStart == "undefined")
            {
                DiscoveryTimeStart = "";
            }
            if (DiscoveryTimeEnd == "undefined")
            {
                DiscoveryTimeEnd = "";
            }
            if (RiskType == "undefined")
            {
                RiskType = "";
            }
            if (RiskLevel == "undefined")
            {
                RiskLevel = "";
            }
            var result = _service.GetRiskFactoryChart(DiscoveryTimeStart, DiscoveryTimeEnd, RiskType, RiskLevel);
            return this.JsonSuccess(result);
        }

        [HttpGet("GetRiskDepartmentChart")]
        [HttpPost("GetRiskDepartmentChart")]
        [PermissionFilter(nameof(YH_StandingBookChartController) + "_" + nameof(YH_StandingBookChartController.GetRiskDepartmentChart), AuthorizationConst.LIST)]
        public async Task<IActionResult> GetRiskDepartmentChart(string DiscoveryTimeStart, string DiscoveryTimeEnd, string RiskType, string RiskLevel)
        {
            if (DiscoveryTimeStart == "undefined")
            {
                DiscoveryTimeStart = "";
            }
            if (DiscoveryTimeEnd == "undefined")
            {
                DiscoveryTimeEnd = "";
            }
            if (RiskType == "undefined")
            {
                RiskType = "";
            }
            if (RiskLevel == "undefined")
            {
                RiskLevel = "";
            }
            var result = _service.GetRiskDepartmentChart(DiscoveryTimeStart, DiscoveryTimeEnd, RiskType, RiskLevel);
            return this.JsonSuccess(result);
        }

        

        [HttpGet("GetRiskTrendLineChart")]
        [HttpPost("GetRiskTrendLineChart")]
        [PermissionFilter(nameof(YH_StandingBookChartController) + "_" + nameof(YH_StandingBookChartController.GetRiskTrendLineChart), AuthorizationConst.LIST)]
        public async Task<IActionResult> GetRiskTrendLineChart(string Level,string DiscoveryTimeStart, string DiscoveryTimeEnd, string RiskType, string RiskLevel, string Department)
        {
            if (Level == "undefined")
            {
                Level = "";
            }
            if (DiscoveryTimeStart == "undefined")
            {
                DiscoveryTimeStart = "";
            }
            if (DiscoveryTimeEnd == "undefined")
            {
                DiscoveryTimeEnd = "";
            }
            if (RiskType == "undefined")
            {
                RiskType = "";
            }
            if (RiskLevel == "undefined")
            {
                RiskLevel = "";
            }
            if (Department == "undefined")
            {
                Department = "";
            }
            var result = _service.GetRiskTrendLineChart(Level,DiscoveryTimeStart, DiscoveryTimeEnd, RiskType, RiskLevel, Department);
            return this.JsonSuccess(result);
        }

        [HttpGet("GetContractorStatistics")]
        [HttpPost("GetContractorStatistics")]
        [PermissionFilter(nameof(YH_StandingBookChartController) + "_" + nameof(YH_StandingBookChartController.GetContractorStatistics), AuthorizationConst.LIST)]
        public async Task<IActionResult> GetContractorStatistics(PagingModel<YH_StandingBookContractorDto> pagingQueryModel)
        {
            IPageModel<YH_StandingBookContractorDto> result = await _service.GetContractorStatistics(pagingQueryModel);
            return this.JsonSuccess(result);
        }
        [HttpGet("GetHiddenTroubleRectification")]
        [HttpPost("GetHiddenTroubleRectification")]
        [PermissionFilter(nameof(YH_StandingBookChartController) + "_" + nameof(YH_StandingBookChartController.GetHiddenTroubleRectification), AuthorizationConst.LIST)]
        public async Task<IActionResult> GetHiddenTroubleRectification(PagingModel<YH_StandingBookHiddenTroubleRectificationDto> pagingQueryModel)
        {
            IPageModel<YH_StandingBookHiddenTroubleRectificationDto> result = await _service.GetHiddenTroubleRectification(pagingQueryModel);
            return this.JsonSuccess(result);
        }

        /// <summary>
        /// 导出
        ///</summary>
        /// <param name="pagingQueryModel"></param>
        /// <returns></returns>

        [HttpPost("ExportHiddenTroubleRectification")]
        [PermissionFilter(nameof(YH_StandingBookController) + "_" + nameof(YH_StandingBookChartController.ExportHiddenTroubleRectification), AuthorizationConst.EXPORT)]
        public async Task<IActionResult>
            ExportHiddenTroubleRectification(PagingModel<YH_StandingBookHiddenTroubleRectificationDto>
                pagingQueryModel)
        {
            var fileName = await _service.ExportHiddenTroubleRectification(pagingQueryModel);
            if (string.IsNullOrWhiteSpace(fileName))
                return this.JsonFaild(NULL_DATA_FOR_EXCEL_EXPORT);
            return this.JsonSuccess(fileName);
        }

        
            [HttpGet("GetRepeatRiskPieChart")]
        [HttpPost("GetRepeatRiskPieChart")]
        [PermissionFilter(nameof(YH_StandingBookChartController) + "_" + nameof(YH_StandingBookChartController.GetRepeatRiskPieChart), AuthorizationConst.LIST)]
        public async Task<IActionResult> GetRepeatRiskPieChart(string Topn, string DiscoveryTimeStart, string DiscoveryTimeEnd, string RiskType, string RiskLevel, string Department)
        {
            if (Topn == "undefined" || Topn == "TOPN")
            {
                Topn = "";
            }
            if (DiscoveryTimeStart == "undefined")
            {
                DiscoveryTimeStart = "";
            }
            if (DiscoveryTimeEnd == "undefined")
            {
                DiscoveryTimeEnd = "";
            }
            if (RiskType == "undefined")
            {
                RiskType = "";
            }
            if (RiskLevel == "undefined")
            {
                RiskLevel = "";
            }
            if (Department == "undefined")
            {
                Department = "";
            }
            var result = _service.GetRepeatRiskPieChart(Topn, DiscoveryTimeStart, DiscoveryTimeEnd, RiskType, RiskLevel, Department);
            return this.JsonSuccess(result);
        }

    }
}
